package com.my12306.train.controller;

import com.my12306.common.model.vo.PageVo;
import com.my12306.common.util.PageUtils;
import com.my12306.common.util.response.ResponseData;
import com.my12306.train.model.entity.MileageEntity;
import com.my12306.train.model.vo.MileageRouteVo;
import com.my12306.train.service.MileageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * 里程api
 *
 * @author wj
 * @email
 * @date 2020-07-24 20:58:07
 */
@RestController
@RequestMapping("/mileage")
public class MileageController {
    @Autowired
    private MileageService mileageService;

    /**
     * 分页查询里程列表
     */
    @PostMapping("/pg/lst")
    public ResponseData list(@RequestBody PageVo pageVo) {
        PageUtils page = mileageService.queryMileageByPage(pageVo);
        return ResponseData.ok().put("page", page);
    }

    @GetMapping("/add/pmts")
    public ResponseData getParamts(@RequestParam(value = "mileageId",required = false) Long mileageId){
      return   mileageService.getAddParamters(mileageId);
    }
    /**
     * 信息
     */
    @GetMapping("/info/{mileageId}")
    public ResponseData info(@PathVariable("mileageId") Long mileageId) {
        MileageEntity mileage = mileageService.getById(mileageId);

        return ResponseData.ok().put("mileage", mileage);
    }

    /**
     * 保存
     */
    @PostMapping("/mrv/sv")
    public ResponseData save(@Valid  @RequestBody MileageRouteVo mileageRouteVo) {
        System.out.println(mileageRouteVo);
        mileageService.saveMileage(mileageRouteVo);
        return ResponseData.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/up")
    public ResponseData update(@Valid@RequestBody MileageEntity mileage) {
        mileageService.updateMileageById(mileage);
        return ResponseData.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/del")
    public ResponseData delete(@RequestBody List<Long> routeId) {
        mileageService.deleteMileageByRouteId(routeId);
        return ResponseData.ok();
    }

}
